package com.jmz.apt.api.Utils;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description : {  List转换工具类 }
 * @Author : create by NanFeng on 2019-11-06 16:12
 */
public class ListUtil {

    /**
     * 将 1,2,3  格式转成 List
     *
     * @param ids ids
     * @return list
     */
    public static List<Long> toLongList(String ids) {
        String[] sids = ids.split(",");
        List<Long> list = new ArrayList<>();
        for (String sid : sids) {
            if (!StringUtils.isEmpty(sid)) {
                list.add(Long.parseLong(sid));
            }
        }
        return list;
    }

    /**
     * 将 1,2,3  格式转成 List
     *
     * @param ids ids
     * @return list
     */
    public static List<Integer> toIntList(String ids) {
        String[] sids = ids.split(",");
        List<Integer> list = new ArrayList<>();
        for (String sid : sids) {
            list.add(Integer.parseInt(sid));
        }
        return list;
    }

    public static String list2String(List list) {
        if (list != null && list.size() > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < list.size(); i++) {
                sb.append(list.get(i)).append(",");
            }
            return sb.toString().substring(0, sb.toString().length() - 1);
        }
        return null;
    }
}
